﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace PostSharpCache
{
    class Program
    {
        
        static void Main(string[] args)
        {
            Console.WriteLine("1—>" + GetDifficultResult(1));
            Console.WriteLine("2—>" + GetDifficultResult(2));
            Console.WriteLine("1—>" + GetDifficultResult(1));
            Console.WriteLine("2—>" + GetDifficultResult(2));
            Console.ReadKey();
        }

        /// <summary>
        /// 加上属性描述符后，每次执行方法时被注入Cache方法里，如果第一步验证缓存中有数据，那么这里的GetDifficultResult()
        /// 就不会被执行
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        [Cache]
        private static int GetDifficultResult(int arg)
        {
            Console.WriteLine("正在执行方法……");
            try
            {
                Thread.Sleep(TimeSpan.FromSeconds(5));
            }
            catch (ThreadInterruptedException ex)
            {

            }

            return arg;
        }
    }
}
